package previous.Test_0126;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Solution {
    //一维前缀和
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        //数据
        int n=in.nextInt();
        //相减
        int q=in.nextInt();
        int[] arr=new int[n+1];
        for (int i = 1; i < n+1; i++) {
            arr[i]=in.nextInt();
        }
        long[] dq=new long[n+1];
        dq[0]=0;
        for (int i = 1; i < n+1; i++) {
            dq[i]=dq[i-1]+arr[i];
        }
        while(q>0){
            int l= in.nextInt();
            int r=in.nextInt();
            System.out.println(dq[r]-dq[l-1]);
            q--;
        }
    }
    //二维前缀和
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int m= in.nextInt();
        int q=in.nextInt();
        int[][] arr=new int[n+1][m+1];
        for (int i = 1; i < n+1; i++) {
            for (int j = 1; j < m+1; j++) {
                arr[i][j]= in.nextInt();
            }
        }
        long[][] dq=new long[n+1][m+1];
        dq[0][0]=0;
        for (int i = 1; i < n+1; i++) {
            for (int j = 1; j < m+1; j++) {
                dq[i][j]=dq[i-1][j]+dq[i][j-1]+arr[i][j]-dq[i-1][j-1];
            }
        }
        while(q>0){
            int x1=in.nextInt(),y1= in.nextInt(),x2=in.nextInt(),y2= in.nextInt();
            System.out.println(dq[x2][y2] - dq[x1 - 1][y2] - dq[x2][y1 - 1] + dq[x1 - 1][y1 - 1]);
            q--;
        }
    }
    //寻找数组的中心下标
    public int pivotIndex1(int[] nums) {
        int len=nums.length;
        int[] dq=new int[len];
        //预处理
        dq[0]=nums[0];
        //前缀
        for (int i = 1; i < len; i++) {
            dq[i]=dq[i-1]+nums[i];
        }
        //后缀
        int dp=0;
        if(dq[len-1]-nums[0]==0){
            return 0;
        }
        int i=1;
        for (; i <len; i++) {
            dp=dq[len-1]-dq[i];
            if(dq[i-1]==dp){
                return i;
            }
        }
        return -1;
    }
    public int pivotIndex(int[] nums) {
        int len=nums.length;
        int[] dq=new int[len];
        int[] dp=new int[len];
        //预处理
        dq[0]=nums[0];
        //前缀
        for (int i = 1; i < len; i++) {
            dq[i]=dq[i-1]+nums[i];
        }
        //后缀
        for (int i = len-2; i >=0; i++) {
            dp[i]=nums[i]+dq[i];
        }
        int i=1;
        for (; i <len; i++) {
            if(dq[i]==dp[i]){
                return i;
            }
        }
        return -1;
    }
    //除自身以外数组的乘积
    public int[] productExceptSelf(int[] nums) {
        int n=nums.length;
        int[] dq=new int[n];
        int[] dp=new int[n];
        dq[0]=1;
        dp[n-1]=1;
        for (int i = 1; i < n; i++) {
            dq[i]=dq[i-1]*nums[i-1];
        }
        for (int i = n-2; i >=0; i--) {
            dp[i]=dp[i+1]*nums[i+1];
        }
        int[] sum=new int[n];
        for (int i = 0; i < n; i++) {
            sum[i]=dq[i]*dp[i];
        }
        return sum;
    }
}
